package pogos

import (
	system2 "MoSkeleton/web/pogos/response/system"
)

type TreeSelect struct {
	/** 节点ID */
	Id uint64 `json:"id,string"`

	/** 节点名称 */
	Label string `json:"label"`

	/** 子节点 */
	Children *[]*TreeSelect `json:"children,omitempty"`
}

func NewTreeSelectByMenu(menuTreeResp *system2.SysMenuTreeResp) *TreeSelect {
	if menuTreeResp == nil {
		return nil
	}
	ts := &TreeSelect{
		Id:    menuTreeResp.ID,
		Label: menuTreeResp.MenuName,
		Children: func() *[]*TreeSelect {
			if menuTreeResp.Children == nil {
				return nil
			}
			tsList := make([]*TreeSelect, 0)
			for _, menu := range menuTreeResp.Children {
				tsList = append(tsList, NewTreeSelectByMenu(menu))
			}
			return &tsList
		}(),
	}
	return ts
}

func NewTreeSelectByDept(deptTreeResp *system2.SysDeptItemResp) *TreeSelect {
	if deptTreeResp == nil {
		return nil
	}
	ts := &TreeSelect{
		Id:    deptTreeResp.ID,
		Label: deptTreeResp.DeptName,
		Children: func() *[]*TreeSelect {
			if deptTreeResp.Children == nil {
				return nil
			}
			tsList := make([]*TreeSelect, 0)
			for _, dept := range *deptTreeResp.Children {
				tsList = append(tsList, NewTreeSelectByDept(dept))
			}
			return &tsList
		}(),
	}
	return ts
}
